//
//  LPFingerPrintViewController.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 17/5/19.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPFingerPrintViewController.h"
#import "LPFingerPrintTableViewCell.h"
#import "LPFingerPrintModel.h"
#import "LPFingerPrintHeaderView.h"
#import <LocalAuthentication/LocalAuthentication.h>
@interface LPFingerPrintViewController ()<UITableViewDelegate,UITableViewDataSource,LPFingerPrintTableViewDelegate>
/**  table  */
@property (strong, nonatomic) UITableView  *tableView;
/**  数据  */
@property (strong, nonatomic) NSArray  *dataSouce;

@end

@implementation LPFingerPrintViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titlelabel.text = @"指纹";
    [self getDataSource];
    [self layoutUI];
}


#pragma mark - 数据
- (void)getDataSource{
    self.dataSouce = [NSArray yy_modelArrayWithClass:[LPFingerPrintModel class] json:@[@{@"title": @"指纹登录", @"detail": @""}]];
    
}


#pragma mark - 界面
- (void)layoutUI{
    [self.view addSubview:self.tableView];
    LPFingerPrintHeaderView *header = [[LPFingerPrintHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 150 * [UIScreen zj_screenHScale])];
    self.tableView.tableHeaderView = header;
}


#pragma mark - 私有方法


#pragma mark - 监听事件

#pragma mark - LPFingerPrintTableViewDelegate
- (void)lpFingerPrintWith:(LPFingerPrintTableViewCell *)cell swithIndex:(NSString *)switchString{
    if ([switchString isEqualToString:@"1"]) {
        LAContext *laContext = [[LAContext alloc] init];
        NSError *error;
        
        if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
            
            [laContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                      localizedReason:@"Touch Id Test"
                                reply:^(BOOL success, NSError *error) {
                                    if (success) {
                                        NSLog(@"success to evaluate");
                                        //do your work
                                    }
                                    if (error) {
                                        NSLog(@"---failed to evaluate---error: %@---", error.description);
                                        //do your error handle
                                    }
                                }];
        }
        else {
            NSLog(@"==========Not support :%@", error.description);
            //do your error handle
        }
    }
}


#pragma mark - UITableViewDataSource,UITableViewDelegate
/**  返回组个数  */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
/**  返回cell个数  */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSouce.count;
}
/**  返回cell高度  */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50 * [UIScreen zj_screenHScale];
}
/**  cell初始化  */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *weizhi = [NSString stringWithFormat:@"%ld-%ld",(long)indexPath.section,(long)indexPath.row];
    LPFingerPrintTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:weizhi];
    if (!cell) {
        cell = [[LPFingerPrintTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:weizhi];
    }
    cell.delegate = self;
    cell.model = self.dataSouce[indexPath.row];
    return cell;
}
/**  cell的点击事件  */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

#pragma mark - 懒加载
/**  初始化tableView  */
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, LP_TopHeight, self.view.bounds.size.width, self.view.bounds.size.height - LP_TopHeight) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.tableFooterView = [UIView new];
        _tableView.backgroundColor = [UIColor themeGrayColor];
    }
    return _tableView;
}




@end
